{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Curve interpolation resampling(曲线插值)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "This method is used for interpolation of non ideal resolution curves and provides multiple interpolation methods该方法用于对非理想分辨率的曲线进行插值，提供多种插值方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.colors as colors\n",
    "import math\n",
    "import seaborn as sns\n",
    "import pylab as pl\n",
    "\n",
    "from mpl_toolkits.axes_grid1 import make_axes_locatable\n",
    "from scipy import interpolate\n",
    "from pandas import set_option\n",
    "set_option(\"display.max_rows\", 15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 使用GPU训练时候，打开下面注释\n",
    "import os\n",
    "# os.environ['CUDA_VISIBLE_DEVICES']='0'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 定义要处理的常规测井资料\n",
    "usual_log_names = [\"AC\",\"CNL\",\"DEN\",\"GR\",\"RD\",\"RS\"]\n",
    "# usual_log_names = [\"DT\",\"DTXX\"]\n",
    "# usual_log_names = [\"DTC\",\"DTS\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Set the resolution for sampling（设定新的分辨率）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 需要提升的分辨率，为插值间点数:\n",
    "# 如果间隔0.1m, aim_resolution = 10； \n",
    "# 间隔0.125m，aim_resolution = 8；\n",
    "# 间隔1m，aim_resolution = 1；以此类推\n",
    "# # 确保目标曲线的分辨率能够和测井的相匹配以制作标签\n",
    "aim_resolution = 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 元素单位表示单位是否是百分比 default False（测井） | True(录井) \n",
    "use_percent = False"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Load csv data（读入原始数据）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 定义是否要使用常规测井资料，True | False\n",
    "use_usual_log = True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "if use_usual_log == True:\n",
    "    data_path = 'data/usual_logs/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# filename 取值例如：'TT1-4500m-5070m_R_0.1524.csv','HP1_4075m-5582m_R_1.csv'\n",
    "filename = 'GY1_R_0.1524m_整段_1700m-2300m.csv'\n",
    "element_logs_file = os.path.join(data_path,filename)\n",
    "# 读取A、B部分共有数据\n",
    "un_process = pd.read_csv(element_logs_file,engine='python',encoding='GBK')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEPTH</th>\n",
       "      <th>DTC</th>\n",
       "      <th>DTS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5617.0753</td>\n",
       "      <td>75.3691</td>\n",
       "      <td>155.1939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5617.2277</td>\n",
       "      <td>74.9615</td>\n",
       "      <td>153.6787</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5617.3801</td>\n",
       "      <td>74.5912</td>\n",
       "      <td>151.0225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5617.5325</td>\n",
       "      <td>73.8546</td>\n",
       "      <td>147.7337</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5617.6849</td>\n",
       "      <td>72.8347</td>\n",
       "      <td>145.1820</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5617.8373</td>\n",
       "      <td>72.5753</td>\n",
       "      <td>144.4313</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5617.9897</td>\n",
       "      <td>73.4508</td>\n",
       "      <td>145.5181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3111</th>\n",
       "      <td>6091.1917</td>\n",
       "      <td>85.1627</td>\n",
       "      <td>169.4444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3112</th>\n",
       "      <td>6091.3441</td>\n",
       "      <td>85.5282</td>\n",
       "      <td>169.5480</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3113</th>\n",
       "      <td>6091.4965</td>\n",
       "      <td>86.9261</td>\n",
       "      <td>175.0535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3114</th>\n",
       "      <td>6091.6489</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3115</th>\n",
       "      <td>6091.8013</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3116</th>\n",
       "      <td>6091.9537</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3117</th>\n",
       "      <td>6092.1061</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3118 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          DEPTH         DTC         DTS\n",
       "0     5617.0753     75.3691    155.1939\n",
       "1     5617.2277     74.9615    153.6787\n",
       "2     5617.3801     74.5912    151.0225\n",
       "3     5617.5325     73.8546    147.7337\n",
       "4     5617.6849     72.8347    145.1820\n",
       "5     5617.8373     72.5753    144.4313\n",
       "6     5617.9897     73.4508    145.5181\n",
       "...         ...         ...         ...\n",
       "3111  6091.1917     85.1627    169.4444\n",
       "3112  6091.3441     85.5282    169.5480\n",
       "3113  6091.4965     86.9261    175.0535\n",
       "3114  6091.6489 -99999.0000 -99999.0000\n",
       "3115  6091.8013 -99999.0000 -99999.0000\n",
       "3116  6091.9537 -99999.0000 -99999.0000\n",
       "3117  6092.1061 -99999.0000 -99999.0000\n",
       "\n",
       "[3118 rows x 3 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除NAN行\n",
    "un_process_YS = un_process.dropna()\n",
    "un_process_YS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3118, 3)\n"
     ]
    }
   ],
   "source": [
    "# 删除重复行\n",
    "un_process_YS = un_process_YS.drop_duplicates(subset='DEPTH', keep='last')\n",
    "# un_process_YS.set_index('DEPTH')\n",
    "print(un_process_YS.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Determine interpolation range（确定插值范围）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEPTH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5617.0753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5617.2277</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5617.3801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5617.5325</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5617.6849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5617.8373</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5617.9897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3111</th>\n",
       "      <td>6091.1917</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3112</th>\n",
       "      <td>6091.3441</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3113</th>\n",
       "      <td>6091.4965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3114</th>\n",
       "      <td>6091.6489</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3115</th>\n",
       "      <td>6091.8013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3116</th>\n",
       "      <td>6091.9537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3117</th>\n",
       "      <td>6092.1061</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3118 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          DEPTH\n",
       "0     5617.0753\n",
       "1     5617.2277\n",
       "2     5617.3801\n",
       "3     5617.5325\n",
       "4     5617.6849\n",
       "5     5617.8373\n",
       "6     5617.9897\n",
       "...         ...\n",
       "3111  6091.1917\n",
       "3112  6091.3441\n",
       "3113  6091.4965\n",
       "3114  6091.6489\n",
       "3115  6091.8013\n",
       "3116  6091.9537\n",
       "3117  6092.1061\n",
       "\n",
       "[3118 rows x 1 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "C_DEPTH = un_process_YS.loc[:,[\"DEPTH\"]]\n",
    "C_DEPTH"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "X = np.array(C_DEPTH)\n",
    "X.shape = (len(X),)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5617.0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[0] = math.floor(X[0])\n",
    "X[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6092.0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[-1] = math.floor(X[-1])\n",
    "X[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DTC</th>\n",
       "      <th>DTS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>75.3691</td>\n",
       "      <td>155.1939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>74.9615</td>\n",
       "      <td>153.6787</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74.5912</td>\n",
       "      <td>151.0225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>73.8546</td>\n",
       "      <td>147.7337</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>72.8347</td>\n",
       "      <td>145.1820</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>72.5753</td>\n",
       "      <td>144.4313</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>73.4508</td>\n",
       "      <td>145.5181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3111</th>\n",
       "      <td>85.1627</td>\n",
       "      <td>169.4444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3112</th>\n",
       "      <td>85.5282</td>\n",
       "      <td>169.5480</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3113</th>\n",
       "      <td>86.9261</td>\n",
       "      <td>175.0535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3114</th>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3115</th>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3116</th>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3117</th>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3118 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             DTC         DTS\n",
       "0        75.3691    155.1939\n",
       "1        74.9615    153.6787\n",
       "2        74.5912    151.0225\n",
       "3        73.8546    147.7337\n",
       "4        72.8347    145.1820\n",
       "5        72.5753    144.4313\n",
       "6        73.4508    145.5181\n",
       "...          ...         ...\n",
       "3111     85.1627    169.4444\n",
       "3112     85.5282    169.5480\n",
       "3113     86.9261    175.0535\n",
       "3114 -99999.0000 -99999.0000\n",
       "3115 -99999.0000 -99999.0000\n",
       "3116 -99999.0000 -99999.0000\n",
       "3117 -99999.0000 -99999.0000\n",
       "\n",
       "[3118 rows x 2 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "if use_usual_log == True:\n",
    "    C_element = un_process_YS.loc[:, usual_log_names]\n",
    "C_element"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5617 6092\n"
     ]
    }
   ],
   "source": [
    "## math.ceil(f) #向上取整, math.floor(f) #向下取整\n",
    "## X_min、X_max可以由用户指定，也可以是当前测井日志中的最大范围\n",
    "# X_min and X_max can be specified by the user, or they can be the maximum range in the current logging log\n",
    "X_min = math.floor(np.min(X))\n",
    "X_max = math.floor(np.max(X))\n",
    "print(X_min, X_max)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# Xnew = np.linspace(X_min, X_max,(X_max - X_min)* resolution + 1)\n",
    "# Xnew = np.linspace(np.min(X),np.max(X),(np.max(X)-np.min(X))* resolution + 1)\n",
    "# 上面的代码由于numpy版本1.问题会报错，https://stackoverflow.com/questions/59801932/raise-typeerror-typeerror-object-of-type-class-numpy-float64-cannot-be-saf\n",
    "\n",
    "Xnew = np.linspace(np.min(X),np.max(X),(X_max-X_min)* aim_resolution + 1)\n",
    "# Xnew"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x axis is right!\n"
     ]
    }
   ],
   "source": [
    "# print(\"Xnew.shape,type(Xnew):\", Xnew.shape,type(Xnew))\n",
    "if (len(Xnew) -((X_max-X_min)* aim_resolution + 1)) == 0:\n",
    "    print(\"x axis is right!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Interpolate and label the curves of each element based on resolution requirements(针对分辨率要求对各元素曲线进行插值制作标签)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "pd_data0 = pd.DataFrame(Xnew,columns=[\"DEPTH\"])\n",
    "pd_data = pd_data0  \n",
    "if use_usual_log == True:\n",
    "    object_names = usual_log_names\n",
    "\n",
    "for i in range(len(object_names)):\n",
    "    element_Y = []\n",
    "    element_Y = C_element.loc[:, object_names[i]]\n",
    "    if use_percent == True:\n",
    "        element_Y = element_Y / 100.\n",
    "    Y = np.array(element_Y)\n",
    "    Y.shape = (len(Y),)\n",
    "    Ynew = np.zeros(len(Xnew))\n",
    "\n",
    "    # for kind in [\"nearest\",\"zero\",\"slinear\",\"quadratic\",\"cubic\"]:#插值方式\n",
    "    #     #\"nearest\",\"zero\"为阶梯插值\n",
    "    #     #slinear 线性插值\n",
    "    #     #\"quadratic\",\"cubic\" 为2阶、3阶B样条曲线插值\n",
    "    #     f=interpolate.interp1d(X,Y,kind=kind)\n",
    "    #     # ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order)\n",
    "    #     Ynew=f(Xnew)\n",
    "    #     pl.plot(Xnew,Ynew,label=str(kind))\n",
    "#     print(Y.shape,type(Y))\n",
    "    method_kind = \"slinear\"\n",
    "    f = interpolate.interp1d(X, Y, kind = method_kind)\n",
    "        # ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order)\n",
    "    Ynew = f(Xnew)\n",
    "#     results.append(Ynew)\n",
    "\n",
    "    pd_data1 = pd.DataFrame(Ynew,columns = [object_names[i]])\n",
    "\n",
    "    pd_data =pd.concat([pd_data,pd_data1],axis=1)\n",
    "#     pd_data1 = pd.DataFrame(Ynew,columns=[element_name[i] +\"_chazhi\"])\n",
    "#     pd_data = pd.concat([pd_data0,pd_data1],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEPTH</th>\n",
       "      <th>DTC</th>\n",
       "      <th>DTS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5617.000</td>\n",
       "      <td>75.369100</td>\n",
       "      <td>155.193900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5617.125</td>\n",
       "      <td>75.145341</td>\n",
       "      <td>154.362104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5617.250</td>\n",
       "      <td>74.907316</td>\n",
       "      <td>153.290030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5617.375</td>\n",
       "      <td>74.603592</td>\n",
       "      <td>151.111389</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5617.500</td>\n",
       "      <td>74.011683</td>\n",
       "      <td>148.435052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5617.625</td>\n",
       "      <td>73.235566</td>\n",
       "      <td>146.184932</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5617.750</td>\n",
       "      <td>72.723893</td>\n",
       "      <td>144.861327</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3794</th>\n",
       "      <td>6091.250</td>\n",
       "      <td>85.302521</td>\n",
       "      <td>169.484032</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3795</th>\n",
       "      <td>6091.375</td>\n",
       "      <td>85.811632</td>\n",
       "      <td>170.664273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3796</th>\n",
       "      <td>6091.500</td>\n",
       "      <td>-2211.635195</td>\n",
       "      <td>-2125.531718</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3797</th>\n",
       "      <td>6091.625</td>\n",
       "      <td>-84303.110014</td>\n",
       "      <td>-84289.289510</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3798</th>\n",
       "      <td>6091.750</td>\n",
       "      <td>-99999.000000</td>\n",
       "      <td>-99999.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3799</th>\n",
       "      <td>6091.875</td>\n",
       "      <td>-99999.000000</td>\n",
       "      <td>-99999.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3800</th>\n",
       "      <td>6092.000</td>\n",
       "      <td>-99999.000000</td>\n",
       "      <td>-99999.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3801 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         DEPTH           DTC           DTS\n",
       "0     5617.000     75.369100    155.193900\n",
       "1     5617.125     75.145341    154.362104\n",
       "2     5617.250     74.907316    153.290030\n",
       "3     5617.375     74.603592    151.111389\n",
       "4     5617.500     74.011683    148.435052\n",
       "5     5617.625     73.235566    146.184932\n",
       "6     5617.750     72.723893    144.861327\n",
       "...        ...           ...           ...\n",
       "3794  6091.250     85.302521    169.484032\n",
       "3795  6091.375     85.811632    170.664273\n",
       "3796  6091.500  -2211.635195  -2125.531718\n",
       "3797  6091.625 -84303.110014 -84289.289510\n",
       "3798  6091.750 -99999.000000 -99999.000000\n",
       "3799  6091.875 -99999.000000 -99999.000000\n",
       "3800  6092.000 -99999.000000 -99999.000000\n",
       "\n",
       "[3801 rows x 3 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Processing interpolated data(对插值后的数据处理)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 数据小于0的变为0\n",
    "for i in range(len(object_names)):\n",
    "    element_value =  pd_data.iloc[:,(i + 1)]\n",
    "    for j in range(len(element_value)):\n",
    "        if element_value[j] < 0:\n",
    "            element_value[j] = 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Save data to csv(结果写入csv)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "import datetime\n",
    "def tid_maker():\n",
    "    return '{0:%Y%m%d%H%M}'.format(datetime.datetime.now())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "高102\n"
     ]
    }
   ],
   "source": [
    "csvfile_name = (filename.split(\".csv\")[0]).split(\"_R_\")[0] #'TT1-4500m-5070m_R_0.1524.csv'\n",
    "print(csvfile_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.125\n"
     ]
    }
   ],
   "source": [
    "print(str(1/aim_resolution))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "start_depth = X_min\n",
    "end_depth = X_max"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "pd_data.to_csv(data_path + csvfile_name + '_new_R_'+ str(1/aim_resolution) + '_'+ str(start_depth) + 'm-'+str(end_depth)+ \"m\" + '.csv',mode='w',index = False,header=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n",
     "is_executing": true
    }
   },
   "outputs": [],
   "source": [
    "print(\"Correcting well logs is finished!!\")\n",
    "print(data_path + csvfile_name + '_new_R_'+ str(1/aim_resolution) + '_'+ str(start_depth) + 'm-'+str(end_depth)+ \"m\" + '.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}